import request from '@/utils/request'

export interface Notification {
  _id: string
  recipient: any
  sender?: {
    _id: string
    name: string
    avatar?: string
  }
  type: 'lesson_published' | 'lesson_liked' | 'comment_received' | 'system'
  title: string
  content: string
  relatedModel?: 'LessonPlan' | 'Comment' | 'User'
  relatedId?: string
  isRead: boolean
  readAt?: string
  createdAt: string
  updatedAt: string
}

export const notificationApi = {
  // 获取通知列表
  getNotifications(params?: {
    page?: number
    limit?: number
    unreadOnly?: boolean
  }) {
    return request.get('/notifications', { params })
  },

  // 获取未读通知数量
  getUnreadCount() {
    return request.get('/notifications/unread-count')
  },

  // 标记通知为已读
  markAsRead(id: string) {
    return request.put(`/notifications/${id}/read`)
  },

  // 标记所有通知为已读
  markAllAsRead() {
    return request.put('/notifications/read-all')
  },

  // 删除通知
  deleteNotification(id: string) {
    return request.delete(`/notifications/${id}`)
  }
}